# Importing Data
SOUTH_AFRICA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Aluminium/Aluminium.xlsx",sheet = "Sheet1", range = "AD1:AD229")

# Checking the Imported Data
View(SOUTH_AFRICA)
# Creating Time Series Data
SOUTH_AFRICA_ts <- ts(SOUTH_AFRICA, start=c(1998,1), end=c(2016,12), frequency=12)
# Viewing and Checking the Created Time Series Data
SOUTH_AFRICA_ts
sum(is.na(SOUTH_AFRICA_ts))
library(forecast)
SOUTH_AFRICA_ts <- tsclean(SOUTH_AFRICA_ts)
SOUTH_AFRICA_ts

# Identification: Plotting the Time Series Data
plot(SOUTH_AFRICA_ts)

# Estimating the appropriate model
SOUTH_AFRICA_ts_model <- auto.arima(SOUTH_AFRICA_ts)
SOUTH_AFRICA_ts_model

# Forecasting
options(max.print=1000000)
SOUTH_AFRICA_ts_forecast <- forecast (SOUTH_AFRICA_ts_model, level=c(95), h=288)
plot(SOUTH_AFRICA_ts_forecast)
SOUTH_AFRICA_ts_forecast             

# Exporting
write.table(SOUTH_AFRICA_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Aluminium/SOUTH_AFRICA_TSA.csv", sep=",")
